function C = D1I(C,CON)
%*** ******************************************************************
%*** * Initializes the equations of motions of Module D1
%*** * Reserved C(3510) locations are 1600-1699
%*** * This module performs the following functions
%*** *
%*** * 1) Define the locations of the state and state derivative
%*** *    variables
%*** * 2) Converts geographic inputs into inertial coordinates
%*** *
%*** * MODIFICATION HISTORY
%*** * 960711 Created by Peter Zipfel
%*** *
%*** ******************************************************************


  persistent dum3 ipl iplv sbie sbii teg tge tgv tie tig tvg vbeg vbei vbii weii ; 
  dvbe=[];psivg=[];thtvg=[];blon=[];blat=[];


  if isempty(ipl), ipl=zeros(1,100); end;
  if isempty(iplv), iplv=zeros(1,100); end;
  if isempty(vbeg), vbeg=zeros(1,3); end;
  if isempty(tge), tge=zeros(3,3); end;
  if isempty(teg), teg=zeros(3,3); end;
  if isempty(sbie), sbie=zeros(1,3); end;
  if isempty(tvg), tvg=zeros(3,3); end;
  if isempty(tgv), tgv=zeros(3,3); end;
  if isempty(tie), tie=zeros(3,3); end;
  if isempty(sbii), sbii=zeros(1,3); end;
  if isempty(tig), tig=zeros(3,3); end;
  if isempty(weii), weii=zeros(3,3); end;
  if isempty(dum3), dum3=zeros(1,3); end;
  if isempty(vbei), vbei=zeros(1,3); end;
  if isempty(vbii), vbii=zeros(1,3); end;

  %*** INPUT DATA INITIALIZATION

  % equivalence(bcom_1(1602),psivgx) ::;
  % equivalence(bcom_1(1603),thtvgx) ::;
  % equivalence(bcom_1(1604),blon) ::;
  % equivalence(bcom_1(1605),blat) ::;
  % equivalence(bcom_1(1606),balt) ::;
  % equivalence(bcom_1(1610),baltft) ::;
  % equivalence(bcom_1(1613),dvbe) ::;

  % PSIVGX = I Heading angle from north - deg
  % THTVGX = I Flight path angle from horizontal - deg
  % BLON = I/G Vehicle longitude - rad
  % BLAT = I/G Vehicle latitude - rad
  % BALT = I/O Vehicle altitude - m
  % BALTFT = I/O Vehicle altitude - ft
  % DVBE = I/G Geographic speed - m/s

  %*** INPUT FROM EXECUTIVE

  % equivalence(bcom_1(0051),rearth) ::;
  % equivalence(bcom_1(0052),crad) ::;
  % equivalence(bcom_1(0058),weii3) ::;
  % equivalence(bcom_1(2562),ipl(1)) ::;
  % equivalence(bcom_1(2867),iplv(1)) ::;
  % equivalence(bcom_1(2561),nip) ::;

  % IPL(100) = E State derivitave bcom_1-array locations
  % IPLV(100) = E State bcom_1-array locations
  % N = E Number of variables to integrate

  %*** INITIALIZATION

  % equivalence(bcom_1(1622),tgv(1,1)) ::;
  % equivalence(bcom_1(1631),tig(1,1)) ::;
  % equivalence(bcom_1(1649),sbii(1)) ::;
  % equivalence(bcom_1(1643),vbii(1)) ::;
  % equivalence(bcom_1(1658),balt0) ::;

  %***  INITIALIZATION OF STATE VARIABLES

  iloc=1640;
  for i=0:2;
  ipl(nip)=fix(iloc+i);
  iplv(nip)=fix(iloc+i+3);
  nip=nip+1;
  end; i=2+1;

  iloc=1646;
  for i=0:2;
  ipl(nip)=fix(iloc+i);
  iplv(nip)=fix(iloc+i+3);
  nip=nip+1;
  end; i=2+1;

  %***INPUT CONVERSION TO SBII AND VBII AND INITIAL TGV AND TIG

  sbie(1)=(balt+rearth).*cos(blat).*cos(blon);
  sbie(2)=(balt+rearth).*cos(blat).*sin(blon);
  sbie(3)=(balt+rearth).*sin(blat);
  [tie]=matuni(tie,3);
  sbii*tie,sbie,3,3,1);

  psivg=psivgx./crad;
  thtvg=thtvgx./crad;
  [vbeg,dvbe,psivg,thtvg]=matcar(vbeg,dvbe,psivg,thtvg);
  [tge,blon,blat]=cadtge3(tge,blon,blat);
  [teg,tge]=mattra(teg,tge,3,3);
  [weii]=matzer(weii,3,3);
  weii(1,2)=-weii3;
  weii(2,1)=weii3;
  dum3*weii,sbii,3,3,1);
  tig*tie,teg,3,3,3);
  vbei*tig,vbeg,3,3,1);
  [vbii,vbei,dum3]=matadd(vbii,vbei,dum3,3,1);
  [tvg,psivg,thtvg]=mat2tr(tvg,psivg,thtvg);
  [tgv,tvg]=mattra(tgv,tvg,3,3);

  %*** SAVE LAUNCH ALTITUDE

  balt0=balt;
  baltft=balt.*3.2808399;

  return;
end %subroutine d1i